package com.shanshan.system.controller;


import com.shanshan.system.entity.News;
import com.shanshan.system.service.INewsService;
import com.shanshan.system.vo.Result;
import com.shanshan.system.vo.SearchAdmin;
import com.shanshan.system.vo.SearchContent;
import io.swagger.annotations.Api;
import io.swagger.models.auth.In;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author shanshan
 * @since 2023-01-31
 */
@RestController
@RequestMapping("/system/news")
@Api(tags = "菜单")
public class NewsController {
    @Autowired
    private INewsService newsService;

    @PostMapping("/addNews")
    public Result addNews(@RequestBody News news){
        return newsService.addNews(news);
    }

    @PostMapping("/list")
    public Result selectAll(@RequestParam(defaultValue = "1") int currentPage, @RequestParam(defaultValue = "5") int pageSize, @RequestBody SearchContent searchContent){
        return newsService.selectAll(currentPage,pageSize,searchContent);
    }

    /**
     * @param news:
     * @return Result
     * @description 审核拒绝修改理由
     */
    @RequestMapping("/refuse")
    public Result refuse(@RequestBody News news){
        System.out.println(news);
        return newsService.refuse(news);
    }

    @RequestMapping("/agree")
    public Result agree(@RequestParam("id") Integer id){
        System.out.println(id);
        return newsService.agree(id);
    }

    /**
     * @param id:
     * @param status:
     * @return Result
     * @description 修改新闻的上下架
     */
    @RequestMapping("/upUpdate")
    public Result upUpdate(@Param("id") int id, @Param("status") int status){
        return newsService.upUpdate(id,status);
    }

    /**
     * @param id:
     * @param uppid:
     * @return Result
     * @description 修改新闻的置顶和取消置顶
     */
    @RequestMapping("/topUpdate")
    public Result topUpdate(@RequestParam("id") int id,@RequestParam("uppid") int uppid){
        return newsService.topUpdate(id,uppid);
    }

    /**
     * @param :
     * @return Result
     * @description  中央党新闻
     */
    @RequestMapping("/newkind1")
    public Result findAllKind1(){
        return newsService.findAllKind1();
    }

    @RequestMapping("/newkind1ById")
    public Result newkind1ById(Integer id){
        return newsService.findAllKind1ById(id);
    }
    /**
     * @param :
     * @return Result
     * @description 党的发展史
     */
    @RequestMapping("/newkind2")
    public Result findAllKind2(){
        return newsService.findAllKind2();
    }

    @RequestMapping("newkind2ById")
    public Result newkind2ById(Integer id){
        return newsService.findAllKind2ById(id);
    }

}
